package com.dingwei.lesyndrome.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.lesyndrome.R;
import com.dingwei.lesyndrome.app.MyApplication;
import com.dingwei.lesyndrome.bean.CollectBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created time 2018/3/7.
 * Creator 南柯一梦丶 on
 * Personal signature 余生还长 何必慌张
 * Page description :
 */

public class NewsCollectAdapter extends RecyclerArrayAdapter<CollectBean.DataBean> {
    public NewsCollectAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new NewsCollectHolder(parent);
    }


    public class NewsCollectHolder extends BaseViewHolder<CollectBean.DataBean> {


        @Bind(R.id.tv_delete)
        TextView tvDelete;
        @Bind(R.id.rowBG)
        LinearLayout rowBG;
        @Bind(R.id.img_head_h)
        ImageView imgHeadH;
        @Bind(R.id.tv_content_h)
        TextView tvContentH;
        @Bind(R.id.tv_count_h)
        TextView tvCountH;
        @Bind(R.id.ll_h)
        LinearLayout llH;
        @Bind(R.id.tv_content_v)
        TextView tvContentV;
        @Bind(R.id.img_1)
        ImageView img1;
        @Bind(R.id.img_2)
        ImageView img2;
        @Bind(R.id.img_3)
        ImageView img3;
        @Bind(R.id.tv_count_v)
        TextView tvCountV;
        @Bind(R.id.ll_v)
        LinearLayout llV;
        @Bind(R.id.rowFG)
        LinearLayout rowFG;

        public NewsCollectHolder(ViewGroup parent) {
            super(parent, R.layout.item_news_collect);
            ButterKnife.bind(this, itemView);


        }

        @Override
        public void setData(CollectBean.DataBean data) {
            super.setData(data);
            if (data.imgList!=null&&data.imgList.size()==1){
                llH.setVisibility(View.VISIBLE);
                llV.setVisibility(View.GONE);

                Glide.with(BaseActivity.context)
                        .load(data.imgList.get(0).img)
                        .apply(MyApplication.options_no_transform)
                        .into(imgHeadH);
                tvContentH.setText(data.title);
                tvCountH.setText(data.views+"人看过");

            }else {
                llH.setVisibility(View.GONE);
                llV.setVisibility(View.VISIBLE);

                switch (data.imgList.size()) {
                    case 1:
                        Glide.with(BaseActivity.context).load(data.imgList.get(0).img).into(img1);
                        break;
                    case 2:
                        Glide.with(BaseActivity.context).load(data.imgList.get(0).img).into(img1);
                        Glide.with(BaseActivity.context).load(data.imgList.get(1).img).into(img2);
                        break;
                    case 3:
                        Glide.with(BaseActivity.context).load(data.imgList.get(0).img).into(img1);
                        Glide.with(BaseActivity.context).load(data.imgList.get(1).img).into(img2);
                        Glide.with(BaseActivity.context).load(data.imgList.get(2).img).into(img3);
                        break;
                }

                tvContentV.setText(data.title);
                tvCountV.setText(data.views+"人看过");
            }
        }
    }
}
